/*
 * $Id$
 */
package corejs;

import corejs.parser.InfixParser;
import corejs.parser.PrefixParser;
import corejs.parser.StatementParser;

import java.util.HashMap;
import java.util.HashSet;

/**
 *
 * @author myang
 */
public enum JsTokenType implements TokenType {

   NAME, STRING, INTEGER, LONG, DECIMAL,

   EOF,

   // reserved words
   BREAK, CASE, CATCH, CONTINUE, ELSE, FALSE, FOR, FUNCTION, IF, NULL, 
   RETURN, SWITCH, TRUE, TRY, TYPEOF, VAR, WHILE, WITH,

   // special symbols
   PLUS("+"), MINUS("-"), STAR("*"), SLASH("/"), ASSIGN("="), PLUS_PLUS("++"),
   EQUAL("=="), NOT_EQUAL("!="), STRICT_EQUAL("==="), STRICT_NOT_EQUAL("!=="),
   PLUS_ASSIGN("+="), MINUS_ASSIGN("-="), MINUS_MINUS("--"),
   STAR_ASSIGN("*="), SLASH_ASSIGN("/="), BANG("!"), BITWISE_AND("&"), 
   BITWISE_OR("|"), AND("&&"), OR("||"),
   QUESTION_MARK("?"), GT(">"), LT("<"), LE("<="), GE(">="),
   DOT("."), COMMA(","), SEMICOLON(";"), COLON(":"), LEFT_PAREN("("),
   RIGHT_PAREN(")"), LEFT_BRACKET("["), RIGHT_BRACKET("]"), LEFT_BRACE("{"),
   RIGHT_BRACE("}"), UP_ARROW("^"), DOT_DOT("..");

   private static final int FIRST_RESERVED_INDEX = BREAK.ordinal();
   private static final int LAST_RESERVED_INDEX = WITH.ordinal();

   private static final int FIRST_SPECIAL_INDEX = PLUS.ordinal();
   private static final int LAST_SPECIAL_INDEX = DOT_DOT.ordinal();

   private String _text;

   /**
    *
    * @param text
    */
   JsTokenType(final String text) { _text = text; }

   /**
    *
    */
   JsTokenType() { _text = toString().toLowerCase(); }

   private PrefixParser _prefixParser;
   private InfixParser _infixParser;
   private StatementParser _stmtParser;

   public static HashSet<String> RESERVED_WORDS2 = new HashSet<String>();

   static {
      JsTokenType values[] = JsTokenType.values();
      for (int i = FIRST_RESERVED_INDEX; i <= LAST_RESERVED_INDEX; ++i) {
         RESERVED_WORDS2.add(values[i]._text.toLowerCase());
      }
   }

   public static final HashMap<String, JsTokenType> 
     RESERVED_WORDS = new HashMap<String, JsTokenType>();
   static {
      JsTokenType values[] = JsTokenType.values();
      for (int i = FIRST_RESERVED_INDEX; i <= LAST_RESERVED_INDEX; ++i) {
         RESERVED_WORDS.put(values[i]._text.toLowerCase(), values[i]);
      }
   }

   public static final HashMap<String, JsTokenType> 
     SPECIAL_SYMBOLS = new HashMap<String, JsTokenType>();

   static {
      JsTokenType values[] = JsTokenType.values();
      for (int i = FIRST_SPECIAL_INDEX; i <= LAST_SPECIAL_INDEX; ++i) {
         SPECIAL_SYMBOLS.put(values[i]._text, values[i]);
      }
   }

   @Override
   public PrefixParser prefix() {return _prefixParser;}

   @Override
   public StatementParser statement() {return _stmtParser;}

   @Override
   public InfixParser infix() {return _infixParser;}

   @Override
   public void infix(final InfixParser p) {_infixParser = p;}

   @Override
   public void prefix(final PrefixParser p) {_prefixParser = p;}

   @Override
   public void statement(final StatementParser p) {_stmtParser = p;}
}
